The present invention relates to a compiler device which can easily prevent generation of an access conflict occurring when object data is accessed from a plurality of threads by automatically serializing the access of the plurality of clients. The present invention also relates to a computer-readable recording medium with a compiler for the compiler device recorded therein.
Conventionally, there has been used a client-server system in which a plurality of clients share an application program on a server for effective use of the resources. In such a client-server system, a thread for launching an application program is generated in response to initiation by a client. When a plurality of threads are generated for one object data in response to initiation by a plurality of clients then there occurs a conflict between the threads. A means and a method for effectively avoiding such an access conflict was required.
FIG. 23 is a block diagram showing configuration of a client-server system based on the conventional technology as described above. The client-server system shown in this figure comprises a server 1, a client 41 and a client 42 each connected to the server 1 via a network 3. In the server 1, an application program AP1 and an application program AP2 are programs each in an execution format with a source program compiled by means of the object-oriented programming, and are started by the client 41 and client 42.
The application program AP1 corresponds to a super class C1 in the object-oriented programming. On the other hand, the application program AP2 corresponds to a subclass C2 inheriting the super class C1. With the inheritance relationship between the two classes, a common area C0 (object data) of the super class C1 is accessed when the application program AP1 and application program AP2 are started. A thread generator 2 generates a thread S1 and a thread S2 to execute the application program AP1 and application program AP2.
In the above-described configuration, when the application program AP1 and application program AP2 in the server 1 are started by the client 41 and client 42, the thread generator 2 generates the thread S1 and thread S2 respectively. When the application program AP1 and application program AP2 are executed, there occurs an access conflict in which the thread S1 and thread S2 concurrently access the common area C0 (object data). In order to prevent the access conflict it is required to provide exclusive controls for serializing the thread S1 and thread S2 so that the thread S1 and thread S2 do not concurrently access the common area C0 (object data). The exclusive controls are the controls for avoiding an access conflict by giving access rights to the common area C0 to the thread S1 (or the thread S2) and giving the access rights to the thread S1 (or the thread S1) when the access from thread S1 terminates.
As an example of the exclusive controls based on the conventional technology, there has been employed a method in which a user of an application program makes a thread acquire a lock to execute the application program. The lock is acquire through a manual input of a command or the like by the user before the application program is executed (this method is described as a first method hereinafter). The application program is executed only by the thread having acquired the lock, and other threads can not execute the application program. When execution of the application program is finished, the lock is released by the user. The application program can then be executed by any other thread. Further, as another example of exclusive controls in the conventional technology, there has been employed a method in which a programmer describes instructions to execute the above-described exclusive controls in the definition of a method when creating the super class C1 and the subclass C2 (This method is described as a second method hereinafter).
As described above, conventionally the exclusive controls are provided by applying the first or second method to avoid an access conflict in which a plurality of threads concurrently access the common area C0 (object data).
In the first method, however, as acquisition/release of a lock is performed manually by a user, the user may sometimes make a mistake such as forget to release the lock, which may in turn cause the trouble that other thread (user) can not access the application program for a long time. Therefore, the first method may lead to lower efficiency in use of an application program, and employment of this method is not always advantageous. Further, in the first method, it is difficult for a user to intentionally provide exclusive controls for a data structure of the application program, especially for a class in which object data exists. To overcome this difficulty, in the first method, the exclusive controls are provided for each application program regardless of presence or absence of object data in the class. However, there may occur a case in which exclusive controls are executed to an application that does not basically require any exclusive controls. In such a case, the use efficiency of the application program is disadvantageously lowered.
In the second method, although instructions are described by a programmer for describing the method to provide the above-described exclusive controls, there is a possibility that incorrect commands for exclusive controls are described due to a human error. In this case, there occurs the trouble that exclusive controls are not executed successfully. Thus, the second method is also not recommendable. As described, the first and second methods require users (including programmers) a heavy work load, yet the methods do not always insure success in prevention of an access conflict.
It is an object of the present invention to provide a compiler device which can easily avoid an access conflict over object data among a plurality of threads without requiring any particular work load to users. It is another object of the present invention to provide a computer-readable recording medium with a compiler recorded therein.
According to one aspect of this invention, when a source program is compiled, a detection unit detects the presence or absence of an object data for a method based on the class definition in the source program. A first incorporation unit incorporates the result of detection into the object program as object-data-retention information. Further, a second incorporation unit incorporates an exclusive-control instruction into the object program. Therefore, when the object program is executed, one of a plurality of threads can only execute the method corresponding to the object data under the exclusive controls.
As described above, the object-data-retention information and exclusive-control instruction are automatically incorporated into the object program during compilation. Therefore, generation of access conflict over object data between a plurality of threads can easily be avoided without imposing any particular burden on the user.
Further, when the source program is compiled, an inheritance-relation check unit checks an inheritance relationship for a class in the source program, a detection unit detects presence or absence of object data for a method of a class inherited by the class. The first incorporation unit then incorporates a result of detection into the object program as the object-data-retention information, and the second incorporation unit incorporates the exclusive-control instruction into the object program. Therefore, when the object program is executed, only one of a plurality of threads can execute the method corresponding to a class inherited by the class under the exclusive controls.
As described above, the inheritance relationship for a class is checked during compilation of the program, and the object-data-retention information and the exclusive-control instruction according to the result of checking are automatically incorporated into the object program. Therefore, generation of access conflict over object data between a plurality of threads can easily be avoided without imposing any particular burden on the user based on considerations to an inheritance relationship for the class.
According to another aspect of this invention, when a source program is compiled, a detection unit detects the presence or absence of an object data for a method based on class definition in the source program, and an incorporation unit incorporates an exclusive-control instruction into an object program. Therefore, when the object program is executed, only one of a plurality of threads can execute the method for which object data is detected under the exclusive controls. In addition, for a method for which object data is not detected, the same method as that described above is executed by the plurality of threads without executing the exclusive controls.
As described above, the exclusive-control instruction is automatically incorporated into the object program during compilation of the object program. Therefore, generation of access conflict over object data between a plurality of threads can easily be avoided without imposing any particular burden on the user.
According to still another aspect of this invention, when a source program is compiled, a detection step is provided in which the presence or absence of an object data is detected based on class definition in the source program, a first incorporation step is provided in which a result of detection is incorporated into the object program as object-data-retention information. Further, a second incorporation step is provided in which an exclusive-control instruction is incorporated into the object program. Therefore, when the object program is executed, only one of a plurality of threads can execute the method corresponding to the object data under the exclusive controls.
As described above, the object-data-retention information and exclusive-control instruction are automatically incorporated into the object program during compilation of the object program. Therefore, generation of access conflict over object data between a plurality of threads can easily be avoided without imposing any particular burden on the user.
Further, when a source program is compiled, an inheritance-relation check step is provided in which an inheritance relationship for a class in the source program is checked, and a detection step is provided in which the presence or absence of an object data for a method of a class inherited by the class is detected. Further, a first incorporation step is provided in which a result of detection is incorporated into the object program as object-data-retention information, and a second incorporation step is provided in which an exclusive-control instruction is incorporated into the object program. Therefore, when the object program is executed, only one thread of a plurality of threads can execute the method of a class inherited by the class under the exclusive controls.
As described above, the inheritance relationship for a class is checked, and the object-data-retention information and exclusive-control instruction according to the result of checking are automatically incorporated into the object program during compilation of the object program. Therefore, generation of access conflict over object data between a plurality of threads can easily be avoided without imposing any particular burden on the user considering an inheritance relationship for the class, which was thought difficult in the conventional technology.
According to still another aspect of this invention, when a source program is compiled, a detection step is provided in which the presence or absence of an object data is detected based on class definition in the source program, and an incorporation step is provided in which an exclusive-control instruction is incorporated into the object program. Therefore, when the object program is executed, only one of a plurality of threads can execute the method for which object data is detected under the exclusive controls. In addition, for the method for which object data is not detected, the same method as described above is executed by the plurality of threads without provision of the exclusive controls therefor.
As described above, the exclusive-control instruction is automatically incorporated into the object program during compilation of the object program. Therefore, generation of access conflict over object data between a plurality of threads can easily be avoided without imposing any particular burden on the user.
Other objects and features of this invention will become apparent from the following description with reference to the accompanying drawings.